package com.dc.project.basics.controller;

import com.dc.common.validated.InsertGroup;
import com.dc.common.validated.QueryGroup;
import com.dc.common.validated.UpdateGroup;
import com.dc.common.vo.ResultVo;
import com.dc.project.basics.dto.BasCategoryDto;
import com.dc.project.basics.entity.BasCategory;
import com.dc.project.basics.service.BasCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 类别表(BasCategory)表控制层
 *
 * @author zhuangcy
 * @since 2021-06-11 14:39:56
 */
@RestController
@RequestMapping("basCategory")
@Api(tags = "类别表")
public class BasCategoryController {
    /**
     * 服务对象
     */
    @Autowired
    private BasCategoryService basCategoryService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    @RequiresPermissions("basics:basCategory:query")
    public ResultVo get(@PathVariable Serializable id) {
        return this.basCategoryService.queryById(id);
    }

    /**
     * 查询类别表列表
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("查询类别表列表")
    @RequiresPermissions("basics:basCategory:query")
    public ResultVo list(@Validated(QueryGroup.class) BasCategoryDto dto) {
        return this.basCategoryService.queryByList(dto);
    }

    /**
     * 新增类别表
     *
     * @param basCategory
     * @return
     */
    @PostMapping
    @ApiOperation("新增类别表")
    @RequiresPermissions("basics:basCategory:add")
    public ResultVo add(@Validated(value = {InsertGroup.class}) @RequestBody BasCategory basCategory) {
        return this.basCategoryService.add(basCategory);
    }

    /**
     * 编辑类别表
     *
     * @param basCategory
     * @return
     */
    @PutMapping
    @ApiOperation("编辑类别表")
    @RequiresPermissions("basics:basCategory:edit")
    public ResultVo edit(@Validated(value = {UpdateGroup.class}) @RequestBody BasCategory basCategory) {
        return this.basCategoryService.edit(basCategory);
    }

    /**
     * 根据主键删除类别表
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除类别表")
    @RequiresPermissions("basics:basCategory:delete")
    public ResultVo delete(@PathVariable Serializable id) {
        return this.basCategoryService.delete(id);
    }

}